﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormNhomKhachHang : Form
    {
        public FormNhomKhachHang()
        {
            InitializeComponent();
            ControlBox = false;
            FormNhomKhachHangLoad();
        }

        public void FormNhomKhachHangLoad()
        {
            DataTable dt = NhomKhachHangDAO.getAll();
            dgvNhomKhachHang.DataSource = dt;
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormNhomKhachHang formNhomKhachHang = this;
            FormChiTietNhomKhachHang formChiTietNhomKhachHang = new FormChiTietNhomKhachHang(ref formNhomKhachHang);
            formChiTietNhomKhachHang.ShowDialog();
        }

        private void dgvNhomKhachHang_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormNhomKhachHang formNhomKhachHang = this;

            NhomKhachHangModel nhomKhachHangModel = new NhomKhachHangModel();
            nhomKhachHangModel.Id = dgvNhomKhachHang.CurrentRow.Cells["Id"].Value.ToString();
            nhomKhachHangModel.Ten = dgvNhomKhachHang.CurrentRow.Cells["Ten"].Value.ToString();
            nhomKhachHangModel.ChietKhau = dgvNhomKhachHang.CurrentRow.Cells["chietKhau"].Value.ToString();
            nhomKhachHangModel.GhiChu = dgvNhomKhachHang.CurrentRow.Cells["ghiChu"].Value.ToString();

            FormChiTietNhomKhachHang formChiTietNhomKhachHang = new FormChiTietNhomKhachHang(nhomKhachHangModel, ref formNhomKhachHang);
            formChiTietNhomKhachHang.ShowDialog();
        }

        private void FormNhomKhachHang_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormNhomKhachHang_KeyDown);
        }

        private void FormNhomKhachHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
